//
//  STGoodView.m
//  赛拓
//
//  Created by 王磊 on 8/7/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STGoodView.h"
#import "STCommodityBean.h"
@interface STGoodView()
@property (nonatomic ,strong) UIImageView *imageView;

@property (nonatomic ,strong) UILabel *introduceLabel;

@property (nonatomic ,strong) UILabel *timeLabel;

@property (nonatomic ,strong) UILabel *priceLabel;

@property (nonatomic ,strong) STCommodityBean *goods;

@property (nonatomic ,strong) UIView *singleline;
@end
@implementation STGoodView

- (void)commitInit {
    [super commitInit];
    UIImageView *imageView = [[UIImageView alloc]init];
    
    self.imageView = imageView;
    
    [self addSubview:imageView];
    
    UILabel *introduceLabel = [[UILabel alloc]init];
    
    introduceLabel.textAlignment = NSTextAlignmentLeft;
    
    introduceLabel.font = ST_13_FONT;
    
    introduceLabel.numberOfLines = 2;
    
    self.introduceLabel = introduceLabel;
    
    [self addSubview:introduceLabel];
    
    UILabel *timeLabel = [[UILabel alloc]init];
    
    timeLabel.textAlignment = NSTextAlignmentLeft;
    
    timeLabel.font = ST_10_FONT;
    
    timeLabel.textColor = ST_999999_COLOR;
    
    self.timeLabel = timeLabel;
    
    [self addSubview:timeLabel];
    
    UILabel *priceLabel = [[UILabel alloc]init];
    
    priceLabel.textAlignment = NSTextAlignmentLeft;
    
    priceLabel.font = ST_13_FONT;
    
    priceLabel.textColor = [UIColor redColor];
    
    self.priceLabel = priceLabel;
    
    [self addSubview:priceLabel];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    
    [self addGestureRecognizer:tap];
    
    UIView *singleline = [[UIView alloc]init];
    
    self.singleline = singleline;
    
    self.singleline.backgroundColor = ST_BG_COLOR;
    
    [self addSubview:singleline];
}
- (void)updateData:(id)data {
    
    STCommodityBean *goods = [STCommodityBean mj_objectWithKeyValues:data];
    
    self.goods = goods;
    
    [self.imageView set_BGBannerImageViewWithString:goods.imgUrl];
    
    self.introduceLabel.text = goods.name;
    
    self.timeLabel.text = goods.time;
    
    self.priceLabel.text = goods.price;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat margin = 15 * ST_SPECIAL_RATE;
    
    self.imageView.frame = CGRectMake(0, 0, self.k_height, self.k_height - 0.5);
    
    self.introduceLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame), margin, self.k_width - CGRectGetMaxX(self.imageView.frame),70 * ST_RATE);
    
    self.timeLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame), CGRectGetMaxY(self.introduceLabel.frame), self.k_width - CGRectGetMaxX(self.imageView.frame), 20);
    
    self.priceLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame), CGRectGetMaxY(self.timeLabel.frame), self.k_width - CGRectGetMaxX(self.imageView.frame), 20);
    self.singleline.frame = CGRectMake(0, self.k_height - 0.5, ST_SCREEN_WIDTH, 0.5);
}
- (void)tap {
    
    [self.mDelegate onItemClick:STItemClickTypeGoods withData:self.goods forIndexPath:nil];
    
}
@end
